package main

import (
	"context"
	"fmt"
	"sync"
	"time"
)

var wg sync.WaitGroup

func cupInfo(ctx context.Context) {

	defer wg.Done()

	for  {
		select {
		case <-ctx.Done():

			return
		default:
			fmt.Println("cpu info")
			time.Sleep(time.Second)
		}

	}

}

func main() {

	wg.Add(1)
	ctx, cannel := context.WithCancel(context.Background())
	go cupInfo(ctx)
	time.Sleep(6 * time.Second)
	cannel()
	wg.Wait()
	fmt.Println("监控完成")

	//cctx := context.WithValue(ctx, "traceid", "123d")
	context.WithTimeout(ctx, time.Second * 5)
	context.WithDeadline(ctx, time.Now().Add(time.Second * 6))
}


